/*    
 * Copyright (c) 2013 ISoftStone, Inc.
 * All right reserved.
 *
 * 文件名：      SystemProperties.java
 * 作者:     Jacky Wang
 * 创建日期： 2013-5-28 下午04:50:23
 * 版本：           
 *
 */
package com.isoftstone.industry.aaa.utils;

import java.io.IOException;
import java.io.InputStream;
import java.sql.SQLException;
import java.util.Locale;
import java.util.Properties;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.hibernate.HibernateException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.isoftstone.industry.common.context.BeanFactory;
import com.isoftstone.industry.aaa.core.service.sysparam.ISysParamInfoService;

/**
 * 系统参数工具类
 * 
 * @author jacky
 */
@Component
public class SystemProperties
{
	private static Logger	logger						= Logger.getLogger(SystemProperties.class);
	
	@Resource
	private  ISysParamInfoService sysParamInfoService ;
	/*private static Locale	logLocale					= Locale.CHINA;

	private static String	sysDefultBillCycleConfigId	= null;
	
	private static String monthChargingMode = null;
	
	private static String fileLockDir = null;

	static
	{
		InputStream in = SystemProperties.class.getClassLoader().getResourceAsStream("system.properties");
		Properties props = new Properties();
		try
		{
			props.load(in);

			String _locale = props.getProperty("log.locale");
			if (_locale != null)
			{
				if ("zh_CN".equalsIgnoreCase(_locale))
				{
					logLocale = Locale.CHINA;
				} else if ("en_US".equalsIgnoreCase(_locale))
				{
					logLocale = Locale.US;
				}
			}
			sysDefultBillCycleConfigId = props.getProperty("system.default.billcycleconfig.id");
			monthChargingMode = props.getProperty("month.charging.mode");
			fileLockDir = props.getProperty("file.lock.dir");
		} catch (IOException e)
		{
			logger.error(e.getMessage(), e);
		}
	}*/
	/*private  ISysParamInfoService getSysParamInfoService() {
		if (sysParamInfoService == null) {
			sysParamInfoService = (ISysParamInfoService) BeanFactory
					.getInstance().getBeanByName("sysParamInfoService");
		}
		return sysParamInfoService;
	}
	*/
	public  Locale getLogLocale()
	{
		 try {
				String _locale = sysParamInfoService.getSysParamInfoById("log.locale").getParaval();
				Locale	logLocale = Locale.CHINA;
				if(_locale !=null){
					if("zh_CN".equalsIgnoreCase(_locale)){
							logLocale = Locale.CHINA;
					}else if("en_US".equalsIgnoreCase(_locale)){
						logLocale = Locale.US;
					}
				}
				return logLocale;
			} catch (HibernateException e) {
				e.printStackTrace();
				return null;
			} catch (SQLException e) {
				e.printStackTrace();
				return null;
			}
		}

	public  String getSysDefultBillCycleConfigId()
	{
		 try {
				return sysParamInfoService.getSysParamInfoById("system.default.billcyclecfg.id").getParaval();
			} catch (HibernateException e) {
				e.printStackTrace();
				return null;
			} catch (SQLException e) {
				e.printStackTrace();
				return null;
			}
		}
	
	public  String getMonthChargingMode()
	{
		 try {
				return sysParamInfoService.getSysParamInfoById("month.charging.mode").getParaval();
			} catch (HibernateException e) {
				e.printStackTrace();
				return null;
			} catch (SQLException e) {
				e.printStackTrace();
				return null;
			}
		}
	
	public  String getFileLockDir(){
		 try {
				return sysParamInfoService.getSysParamInfoById("file.lock.dir").getParaval();
			} catch (HibernateException e) {
				e.printStackTrace();
				return null;
			} catch (SQLException e) {
				e.printStackTrace();
				return null;
			}
		}
}
